#include "blood.h"
#include <QPainter>
#include "enemy.h"
#include <QtDebug>
Blood::Blood()
{
    buttomMap = QPixmap(":/pictures/enemy/radius_back.png");
    fillMap = QPixmap(":/pictures/enemy/radius_front.png");
    f = QFont("Microsoft YaHei", 10, QFont::Bold);
    this->Exist=false;


}

void Blood::notify()
{
    this->Exist=false;
}

void Blood::SetEnemy(enemy *object)
{
    this->_object=object;
    this->setMinimum(0);
    this->setMaximum(this->_object->GetLife());
    this->cur=this->_object->GetLife();
    this->Exist=true;
    rect = QRect(this->_object->GetX(), this->_object->GetY()-10, 60, 15);
    textRect = QRect(this->_object->GetX(), this->_object->GetY()-10, 60, 15);
}

void Blood::setMinimum(int data)
{
    this->Minimum=data;
}

void Blood::setMaximum(int data)
{
    this->Maximum=data;
}

void Blood::Updata(QPainter* p)
{
    this->k=(double)((this->_object->GetLife()-this->Minimum))/(this->Maximum-this->Minimum);
    x=(int)(rect.width()*k);
    fillRect = rect.adjusted(0, 0, x-rect.width(), 0);
    //画进度条
    rect.moveTo(this->_object->GetX(), this->_object->GetY()-10);
    textRect.moveTo(this->_object->GetX(), this->_object->GetY()-10);
    fillRect.moveTo(this->_object->GetX(), this->_object->GetY()-10);
    p->drawPixmap(rect, buttomMap);
    p->drawPixmap(fillRect, fillMap);
    //画文字
    p->setFont(f);
    p->setPen(QColor("#555555"));
    p->drawText(textRect, Qt::AlignCenter, valueStr);
    valueStr = QString("%1%").arg(QString::number(int(k*100)));

}

bool Blood::IfExist()
{
    return this->Exist;
}

Blood::~Blood()
{
    qDebug()<<"delete blood"<<endl;
}
